package tr.richfacesext.components.texttoimg;

import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

/**
 * 
 * @author mert
 *
 */
public class TextToImg extends UIOutput{

	public static final String COMPONENT_TYPE = "tr.richfacesext.components.TextToImg";
	public static final String COMPONENT_FAMILY = "tr.richfacesext.components";
	private static final String DEFAULT_RENDERER = "tr.richfacesext.components.texttoimg.TextToImgRenderer";

	private String _fontName;
	private String _fontStyle;
	private Integer _fontSize;
	private String _style;
	private String _onclick;

	public TextToImg() {
		setRendererType(DEFAULT_RENDERER);
	}

	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public String getFontName() {
		if(_fontName != null )
			return _fontName;

		ValueBinding vb = getValueBinding("fontName");
		return vb != null ? (java.lang.String) vb.getValue(getFacesContext()) : "Verdana";
	}
	public void setFontName(String fontNameValue) {
		_fontName = fontNameValue;
	}

	public String getFontStyle() {
		if(_fontStyle != null )
			return _fontStyle;

		ValueBinding vb = getValueBinding("fontStyle");
		return vb != null ? (java.lang.String) vb.getValue(getFacesContext()) : "plain";
	}
	public void setFontStyle(String fontStyleValue) {
		_fontStyle = fontStyleValue;
	}

	public Integer getFontSize() {
		if(_fontSize != null )
			return _fontSize;

		ValueBinding vb = getValueBinding("fontSize");
		return vb != null ? (java.lang.Integer) vb.getValue(getFacesContext()) : 12;
	}
	public void setFontSize(Integer fontSizeValue) {
		_fontSize = fontSizeValue;
	}

	public String getStyle() {
		if(_style != null )
			return _style;

		ValueBinding vb = getValueBinding("style");
		return vb != null ? (java.lang.String) vb.getValue(getFacesContext()) : null;
	}
	public void setStyle(String styleValue) {
		_style = styleValue;
	}

	public String getOnclick() {
		if(_onclick != null )
			return _onclick;

		ValueBinding vb = getValueBinding("onclick");
		return vb != null ? (java.lang.String) vb.getValue(getFacesContext()) : null;
	}
	public void setOnclick(String onclickValue) {
		_onclick = onclickValue;
	}

	public Object saveState(FacesContext context) {
		Object values[] = new Object[6];
		values[0] = super.saveState(context);
		values[1] = _fontName;
		values[2] = _fontStyle;
		values[3] = _fontSize;
		values[4] = _style;
		values[5] = _onclick;
		return ((Object) values);
	}
	public void restoreState(FacesContext context, Object state) {
		Object values[] = (Object[]) state;
		super.restoreState(context, values[0]);
		_fontName = (String) values[1];
		_fontStyle = (String) values[2];
		_fontSize = (Integer) values[3];
		_style = (String) values[4];
		_onclick = (String) values[5];
	}
}